<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'basic';
$return=array();
/*******basic*******/
if($_RQ['op']=='basic'){
	if($_RQ['postdata']){
		$postdata=get_postdata();
		if(!$postdata['ordersn']){
			exi('请输入订单号！','error');
		}
		if(!$postdata['aliapp_id']){
			exi('请选择上链支付宝小程序！','error');
		}
		if(!$postdata['realname'] || !$postdata['cardnum'] || !$postdata['image'] || !$postdata['backimage']){
			exi('请完成用户信息！','error');
		}
		$order=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>$postdata['ordersn']));
		$image=@file_get_contents(tomedia($postdata['image']));
		$imagehash=hash("sha256", $image);
		$backimage=@file_get_contents(tomedia($postdata['backimage']));
		$backimagehash=hash("sha256", $backimage);
		$cardinfo=array(
			'image'=>$postdata['image'],
			'backimage'=>$postdata['backimage'],
			'imagehash'=>$imagehash,
			'backimagehash'=>$backimagehash,
		);
		$update=array(
				'realname'=>$postdata['realname'],
				'cardnum'=>$postdata['cardnum'],
				'cardinfo'=>ijson_encode($cardinfo),
		);
		pdo_update('core_members',$update,array('id'=>$order['mid']));
		$this->model('member')->up_member($order['id']);
		$bizContent=$this->model('member')->orderinfo($order['ordersn']);
		$hash=$this->model('model')->biznotary($bizContent['hash']);
		$bizContent['leaseServiceFileHash']=$hash;
		$res=$this->model('model')->upinfo($bizContent,'order','',true);
		$api_data=json_decode($order['api_data'],true);
		$api_data['liandata']=$res;
		$api_data['leaseServiceFileHash']=$hash;
		pdo_update('jy_weishop_order',array('api_data'=>ijson_encode($api_data)),array('id'=>$order['id']));
		$bizContent=$this->model('member')->ordergoodsinfo($order['id']);
		$res=$this->model('model')->upinfo($bizContent,'orderProduct','',true);
		$api_data['isshlian']=1;
		pdo_update('jy_weishop_order',array('api_data'=>ijson_encode($api_data)),array('id'=>$order['id']));
		exi('上链成功！');
	}
	$return['item']=$this->plugin_setting('basic');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'上链敲门链',
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'上链敲门链',
				'list'=>array(
					array('type'=>'tip','title'=>'<red>PHP必须7.2以上</red>
					</br>蚂蚁区块链，有个莫名的要求：需要上链一次测试数据，其他很多接口才能正常使用！
					'),
					array('type'=>'select','title'=>'选择上链支付宝小程序','name'=>'aliapp_id','options'=>'apps','help'=>'目前主要是支付宝小程序要上链'),
					array('type'=>'string','title'=>'输入订单号','name'=>'ordersn','help'=>''),
					array('type'=>'string','title'=>'真实姓名','name'=>'realname','help'=>''),
					array('type'=>'string','title'=>'用户身份证号','name'=>'cardnum','help'=>''),
					array('type'=>'image','title'=>'身份证正面','name'=>'image','help'=>''),
					array('type'=>'image','title'=>'身份证正面','name'=>'backimage','help'=>''),
				)
			),
		),
	);
	$return['apps']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
